package com.pig4cloud.pig.base.controller;

import com.pig4cloud.pig.base.api.vo.ConfigVO;
import com.pig4cloud.pig.base.service.ConfigurationCenterService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import javax.validation.Valid;
import java.util.List;

/**
 * @author xuzhuang
 * @since 2024年5月31日13:44:08
 */
@RestController
@AllArgsConstructor
@RequestMapping("/config")
@Tag(description = "config", name = "配置中心模块")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ConfigurationCenterController {

	@Autowired
	private ConfigurationCenterService configurationCenterService;

	/**
	 * 配置中心列表展示
	 */
	@Inner(false)
	@GetMapping("/list")
	@Operation(summary = "分页查询", description = "分页查询")
	public R list(@ParameterObject Page page,@ParameterObject ConfigVO configVO){
		Page page1 = configurationCenterService.selectConfigurCenterList(page, configVO);
		return R.ok(page1);
	}
	/**
	 * 通过id查询配置信息表
	 * @param dataId id
	 * @return R
	 */
	@Inner(false)
	@Operation(description = "通过id查询", summary = "通过id查询")
	@GetMapping("/details/{dataId}")
	public R getById(@PathVariable("dataId") String dataId) {
		return R.ok(configurationCenterService.getById(dataId));
	}

	@Inner(false)
	@Operation(description = "配置中心编辑", summary = "配置中心编辑")
	@PutMapping("/update")
	public R update(@RequestBody ConfigVO configVO) {
		return R.ok(configurationCenterService.update(configVO));
	}

}
